<template>
	<el-dialog title="发送消息" width="50%" :visible.sync="visible" :before-close="handleClose">
		<el-form ref="form" :model="form" :rules="rules"  label-width="80px">
			<el-form-item label="内容" prop="question">
				<el-input type="textarea" :rows="3" placeholder="请填写您要发送的内容..." v-model="form.question" />
			</el-form-item>
		</el-form>
		<span slot="footer" class="dialog-footer">
			<el-button type="default" @click="close">关 闭</el-button>
			<el-button type="primary" @click="send">发 送</el-button>
	  	</span>
	</el-dialog>
</template>

<script>
import { subscribeCustomer } from '@/api/subscribe'

export default {
	props: {
		currentUserId: {},
		type: {}
	},
	data() {
		return {
			visible: true,
			form: {
				userId: this.currentUserId,
				question: undefined,
				type: this.type
			},
			rules: {
				question: [
					{ required: true, message: '请填写要发送给用户的内容', trigger: 'blur' }
				]
			}
		};
	},
	mounted() {

	},
	methods: {
		close() {
			this.$emit('close')
		},
		handleClose() {
			this.$emit('close')
		},
		send() {
			this.$refs['form'].validate((valid) => {
				if (valid) {
					subscribeCustomer(this.form).then(res => {
						if(res.code == 200) {
							this.msgSuccess('发送成功');
							this.$emit('close');
						}
					})
				} else {
					return false;
				}
			});
		}
	}
}
</script>

<style lang="scss" scoped>

</style>
